<template>
  <div id="scroll-component" ref="wraper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll"

export default {
  name: "Scroll",
  props: {
    probetype: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      scroll: null,
    }
  },
  mounted() {
    //创建better-scroll实例
    this.scroll = new BScroll(this.$refs.wraper, {
      click: true,
      scrollY: true,
      pullUpLoad: true,
      mouseWheel: true,
      probeType: this.probetype,
    })

    this.scroll.on("scroll", (position) => {
      this.$emit("sendScroll", position)
    })
  },
  updated() {
    this.scroll.refresh()
  },
  methods: {
    gotop(x = 0, y = 0, time = 2000) {
      //scrollTo是better-scroll内置函数 用于回到指定位置
      this.scroll.scrollTo(x, y, time)
    },
  },
}
</script>

<style lang="less" scoped></style>
